{extend name="public:base"}
{block name='css'}
{/block}

{block name='body'}
<div class="view view-main white-navbar white-toolbar">
    <div data-name="home" class="page">

        <div class="navbar">
            <div class="navbar-inner">
                <div class="left"><a href="{$back}" class="external"><i class="iconfont icon-fanhui"></i></a></div>
                <div class="center"><span>收货地址</span></div>
                <div class="right"></div>
            </div>
        </div>

        <div class="page-content padding-bottom50 ">

            <div class="addlist address-list" >
                {volist name='list' id='vo'}
                <div class="li">
                    <div class="m">
                        <div class="z">
                            <p class="p1">{$vo.name}<span>{$vo.tel}</span></p>
                            <p class="p2">{$vo.sca_name} {$vo.address}</p>
                        </div>
                    </div>
                    <div class="cc">
                        <label class="radio color-green"><input type="radio" name="id" value="{$vo.id}" onchange="defaultThis(this);" {eq name="vo.is_default" value="1"}checked="true"{/eq}><i class="icon-radio"></i></label>
                        <a href="javascript:;" onclick="delCon(this, {$vo['id']})" class="external">删除</a>
                        <a href="{:url('save_address', ['id'=>$vo['id']])}" class="external">编辑</a>
                    </div>
                </div>
                {/volist}
            </div>

        </div>

        <div class="toolbar" onclick="self.location='{:url('save_address')}';">
            <a href="javascript:;" class="add-address"><i class="iconfont icon-tianjia"></i> 添加收货地址</a>
        </div>


    </div>
</div>
{/block}

{block name="js"}
<script>
    function defaultThis(self) {
        if (!$(self).is(':checked')) {
            return false;
        }
        $.post("{:url('setDefault')}", {id:self.value}, function(data){}, 'json');
    }
    function delCon(self, id) {
        app.dialog.confirm("您确定要删除该地址吗？", function(){
            $.post( "{:url('delAddress')}" , {id:id}, function ( data ) {
                if (data.status == 'y') {
                    $(self).parents('.li').remove();
                } else {
                    messageToast(data.info);
                }
            }, "json");
        });
    }
</script>
{/block}